/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dds2.serviceSystem.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dds2.ServicesSystem.Enum.TransactionState;
import mx.its.dds2.ServicesSystem.Modelo.Tarrain;
import mx.its.dds2.serviceSystem.Dao.TarrainDaoLocal;

/**
 *
 * @author Carlos Asis
 */
@Stateless
public class TerrainBl implements TerrainBlLocal {

    @EJB
    private TarrainDaoLocal tarrainDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public TransactionState register(Tarrain terrain) {
     tarrainDao.create(terrain);
     return  TransactionState.COMPLETE;
   
    }

    @Override
    public TransactionState modify(Tarrain terrain) {
        if (terrain.getId() == null || tarrainDao.find(terrain.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            tarrainDao.edit(terrain);
            return TransactionState.COMPLETE;
        }
    }

    @Override
    public TransactionState delete(Tarrain terrain) {
        if (terrain.getId() == null || tarrainDao.find(terrain.getId()) == null) {
            return TransactionState.INCOMPLETE;
        } else {
            tarrainDao.remove(terrain);
            return TransactionState.COMPLETE;
        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public List<Tarrain> getListAll() {
        return tarrainDao.findAll();
    }
}
